home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / dnet / dshterm1_0.lha / lib / st / extrastring.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  2.3 KB  |  71 lines

  1. #include <string.h>
  2.  
  3. /*********************************************************/
  4.         short charinstr(char c, char *string)
  5. /*********************************************************
  6.     Return true if c is in string otherwise return false
  7. **********************************************************/
  8. {    for(;*string; string++) if(c == *string) return(1);
  9.     return(0); }
  10.  
  11.  
  12. /*********************************************************/
  13.             char *strupper(char *string)
  14. /*********************************************************
  15.     Makes string uppercase (return same string)
  16. **********************************************************/
  17. {    char *savestring = string;
  18.     for(;*string; string++) if((*string>='a') && (*string<='z'))
  19.                                 *string -= 'a' - 'A';
  20.     return(savestring); }
  21.  
  22.  
  23. /**********************************************************/
  24. short CmpString(char *cmd, char *table[], long n, long dist)
  25. /**********************************************************
  26.      Test a string against a table of string pointers,
  27.   using every 'dist' pointer for a total of 'n' compares
  28.                    return -1 on fail
  29.          otherwise the index (ith compare ie 0, 1, 2 ... )
  30.  **********************************************************/
  31. {
  32. short i, j;
  33.     for(i = 0, j = 0; i < n; i++)
  34.         if(table[j] && (strncmp(cmd, table[j], strlen(table[j])) == 0)) return(i);
  35.         else j += dist;
  36.     return(-1);
  37. }
  38.  
  39.  
  40. /**********************************************************/
  41. char            *FindChar(char *string, char *instring)
  42. /**********************************************************
  43.   Find first character of 'string' contained in 'instring'
  44.  **********************************************************/
  45. {
  46. short i, j;
  47.     if(!(string && instring)) return(0);
  48.     for(i = 0; string[i]; i++)
  49.         for(j = 0; instring[j]; j++)
  50.             if(string[i] == instring[j]) return(&string[i]);
  51.     return(0);
  52. }
  53.  
  54.  
  55. /**********************************************************/
  56. char            *SkipChar(char *string, char *instring)
  57. /**********************************************************
  58. Find first character of 'string' not contained in 'instring'
  59.  **********************************************************/
  60. {
  61. short i, j;
  62.     if(!(string && instring)) return(0);
  63.     for(i = 0; string[i]; i++) {
  64.         for(j = 0; instring[j] && (instring[j] != string[i]); j++);
  65.         if(instring[j] == '\0') return(&string[i]);
  66.     }
  67.     return(0);
  68. }
  69.  
  70.  
  71.